Nuweb works with any programming language and LATEX [#!latex!#]. I wanted to use LATEX because it supports a multi-level sectioning scheme and has facilities for drawing figures. I wanted to be able to work with arbitrary programming languages because my friends and I write programs in many languages (and sometimes combinations of several languages), e.g., C, Fortran, C++, yacc, lex, Scheme, assembly, Postscript, and so forth. The need to support arbitrary programming languages has many consequences:
WEB
and CWEB
are able to
pretty print the code sections of their documents because they
understand the language well enough to parse it. Since we want to use
any language, we've got to abandon this feature.
WEB
knows about Pascal,
it is able to construct an index of all the identifiers occurring in
the code sections (filtering out keywords and the standard type
identifiers). Unfortunately, this isn't as easy in our case. We don't
know what an identifiers looks like in each language and we certainly
don't know all the keywords. (On the other hand, see the end of
Section 1.3)
WEB
are
concerned with control of the automatic pretty printing. Since we
don't pretty print, many commands are eliminated. A further set of
commands is subsumed by LATEX and may also be eliminated. As a
result, our set of commands is reduced to only four members (explained
in the next section). This simplicity is also reflected in
the size of this tool, which is quite a bit smaller than the tools
used with other approaches.
tangle
and weave
into
a single program that performs both functions at once.
A further reduction in compilation time is achieved by first
writing each output file to a temporary location, then comparing the
temporary file with the old version of the file. If there is no
difference, the temporary file can be deleted. If the files differ,
the old version is deleted and the temporary file renamed. This
approach works well in combination with make
(or similar tools),
since make
will avoid recompiling untouched output files.